package blog

import (
	"Blog/database"
	"Blog/model"
	"github.com/kataras/iris/v12"
	"html/template"
)

// Content /**
type Content struct {
	Id, Title, MenuId, CreateTime, Hits string
	Content                             template.HTML
}

func Article(ctx iris.Context) {
	ctx.ViewData("Config", model.Configs)
	id, _ := ctx.Params().GetInt("id")
	line := Content{}
	rows, _ := database.Db.Query("select `id`,`menu_id`,`title`,`content`,`create_time`,`hits` from amibk_article where id = ?", id)
	for rows.Next() {
		err := rows.Scan(&line.Id, &line.MenuId, &line.Title, &line.Content, &line.CreateTime, &line.Hits)
		if err != nil {
			return
		}
	}
	//fmt.Println(line)
	ctx.ViewData("Content", line)
	ctx.ViewData("Config", model.Configs)
	ctx.ViewData("menu", model.Menus)
	ctx.ViewData("MenuId", line.MenuId)
	err := ctx.View("blog-post.html")
	_, _ = database.Db.Query("UPDATE amibk_article SET `hits`=`hits`+1 WHERE `id` = ?", id)
	if err != nil {
		return
	}
}
